<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!--
 * FCKeditor - The text editor for Internet - http://www.fckeditor.net
 * Copyright (C) 2003-2007 Frederico Caldeira Knabben
 *
 * == BEGIN LICENSE ==
 *
 * Licensed under the terms of any of the following licenses at your
 * choice:
 *
 *  - GNU General Public License Version 2 or later (the "GPL")
 *    http://www.gnu.org/licenses/gpl.html
 *
 *  - GNU Lesser General Public License Version 2.1 or later (the "LGPL")
 *    http://www.gnu.org/licenses/lgpl.html
 *
 *  - Mozilla Public License Version 1.1 or later (the "MPL")
 *    http://www.mozilla.org/MPL/MPL-1.1.html
 *
 * == END LICENSE ==
 *
 * Image dialog window.
-->
<html>
<head>
	<title>Image Properties</title>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<meta name="robots" content="noindex, nofollow" />
	<script type="text/javascript">

var oEditor		= window.parent.InnerDialogLoaded() ;
var FCK			= oEditor.FCK ;
var FCKLang		= oEditor.FCKLang ;
var FCKConfig	= oEditor.FCKConfig ;
var FCKRegexLib	= oEditor.FCKRegexLib ;
var FCKTools	= oEditor.FCKTools ;

document.write( '<script src="' + FCKConfig.BasePath + 'dialog/common/fck_dialog_common.js" type="text/javascript"><\/script>' ) ;
// redeclare global vars for current iframe, so that AC will work
var wgServer = window.top.wgServer;
var wgScriptPath = window.top.wgScriptPath;
var wgTitle = window.top.wgTitle;
// check if AC class exists in top window, then assume Halo is installed, and include the necessary scripts
if (typeof window.top.AutoCompleter != 'undefined') {
    document.write( '<script src="' + wgScriptPath + '/extensions/SMWHalo/scripts/ajaxhalo.js" type="text/javascript"><\/script>' ) ;
    document.write( '<script src="' + wgScriptPath + '/extensions/SMWHalo/scripts/prototype.js" type="text/javascript"><\/script>' ) ;
    document.write( '<script src="' + wgScriptPath + '/extensions/SMWHalo/scripts/OntologyBrowser/generalTools.js" type="text/javascript"><\/script>' ) ;
    document.write( '<script src="' + wgScriptPath + '/extensions/SMWHalo/scripts/Logger/smw_logger.js" type="text/javascript"><\/script>' ) ;
    document.write( '<script src="' + wgScriptPath + '/extensions/SMWHalo/scripts/Autocompletion/wick.js" type="text/javascript"><\/script>' ) ;
    document.write( '<link rel="stylesheet" href="' + wgScriptPath + '/extensions/SMWHalo/skins/Autocompletion/wick.css" type="text/css" \/>' ) ;
}

	</script>
	<script type="text/javascript">

// Get the selected image (if available).
var oImage = FCK.Selection.GetSelectedElement() ;

if ( oImage && oImage.tagName != 'IMG' )
	oImage = null ;

window.onload = function()
{
	// Translate the dialog box texts.
	oEditor.FCKLanguageManager.TranslatePage(document) ;

	// Load the selected element information (if any).
	LoadSelection() ;

	//	UpdateOriginal() ;

	window.parent.SetAutoSize( true ) ;
	window.parent.SetOkButton( true ) ;
}

function LoadSelection()
{
	if ( ! oImage ) return ;

	var sUrl = GetAttribute( oImage, '_fcksavedurl', '' ) ;
	if ( sUrl.length == 0 )
		sUrl = GetAttribute( oImage, 'src', '' ) ;

	GetE('txtUrl').value    = GetAttribute( oImage, '_fck_mw_filename', '' ) ;
	GetE('txtAlt').value    = GetAttribute( oImage, 'alt', '' ) ;
	GetE('xType').value		= GetAttribute( oImage, '_fck_mw_type', '' ) ;
	GetE('cmbAlign').value  = GetAttribute( oImage, '_fck_mw_location', '' ) ;

	GetE('txtWidth').value  = GetAttribute( oImage, '_fck_mw_width', '' ) ;
	GetE('txtHeight').value = GetAttribute( oImage, '_fck_mw_height', '' ) ;

	UpdatePreview();
}

//#### The OK button was hit.
function Ok()
{
	if ( GetE('txtUrl').value.length == 0 )
	{
		GetE('txtUrl').focus() ;
		return false ;
	}

	window.parent.document.getElementById( 'btnOk' ).disabled = true ;
	window.parent.document.getElementById( 'btnCancel' ).disabled = true ;

	var imgName		= GetE('txtUrl').value ;
	var imgCaption	= GetE('txtAlt').value ;
	var imgType		= GetE('xType').value ;
	var imgLocation	= GetE('cmbAlign').value ;
	var imgWidth	= GetE('txtWidth').value ;
	var imgHeight	= GetE('txtHeight').value ;

	var ajaxArg = imgName ;

	if ( imgType.length > 0 )
		ajaxArg += '|' + imgType ;

	if ( imgLocation.length > 0 )
		ajaxArg += '|' + imgLocation ;

	if ( imgWidth.length > 0 )
	{
		ajaxArg += '|' + imgWidth ;

		if ( imgHeight.length > 0 )
			ajaxArg += 'x' + imgHeight ;

		ajaxArg += 'px' ;
	}

	if ( imgCaption.length > 0 )
		ajaxArg += '|' + imgCaption ;

	oEditor.window.parent.sajax_request_type = 'GET' ;
	oEditor.window.parent.sajax_do_call( 'wfSajaxGetImageUrl', [ajaxArg], UpdateImageFromAjax ) ;

	return false ;
}

function UpdateImageFromAjax( response )
{
    window.parent.document.getElementById( 'btnOk' ).disabled = false ;
    window.parent.document.getElementById( 'btnCancel' ).disabled = false ;

	var bHasImage = ( oImage != null ) ;

	if ( !bHasImage )
		oImage = FCK.CreateElement( 'IMG' ) ;
	else
		oEditor.FCKUndo.SaveUndoStep() ;

	UpdateImage( oImage, response.responseText ) ;

	// Call it using setTimeout to avoid a strange behavior in Firefox.
	window.setTimeout( window.parent.Cancel, 0 ) ;
}

function UpdateImage( e, realUrl )
{
	var imgType = GetE('xType').value ;
	var imgLocation = GetE('cmbAlign').value ;

	SetAttribute( e, "_fck_mw_filename", GetE('txtUrl').value ) ;
	SetAttribute( e, "alt", GetE('txtAlt').value ) ;
	SetAttribute( e, "_fck_mw_type", imgType ) ;
	SetAttribute( e, "_fck_mw_location", imgLocation ) ;
	SetAttribute( e, "_fck_mw_width", GetE('txtWidth').value ) ;
	SetAttribute( e, "_fck_mw_height", GetE('txtHeight').value ) ;

	SetAttribute( e, "width" , GetE('txtWidth').value ) ;
	SetAttribute( e, "height", GetE('txtHeight').value ) ;

	if ( imgType == 'thumb' || imgType == 'frame' )
	{
		e.className = 'fck_mw_frame' ;

		if ( imgLocation.length == 0 )
			imgLocation = 'right' ;
	}

	if ( imgLocation.length > 0 )
		e.className += ' fck_mw_' + imgLocation ;

	if ( realUrl.length == 0 )
	{
		e.className += ' fck_mw_notfound' ;
		realUrl = 'about:blank' ;
	}

	e.src = realUrl ;
	SetAttribute( e, "_fcksavedurl", realUrl ) ;
}

var searchTimer ;

//#### Called while the user types the URL.
function OnUrlChange()
{
	var link = GetE('txtUrl').value.Trim() ;

	if ( searchTimer )
		window.clearTimeout( searchTimer ) ;

	if ( link.length < 3  )
	{
		ClearSearch() ;

		if ( link.length == 0 )
			SetSearchMessage( 'start typing in the above field' ) ;
		else
			SetSearchMessage( 'too short... type more' ) ;
		return ;
	}

	SetSearchMessage( 'stop typing to search' ) ;
	searchTimer = window.setTimeout( StartSearch, 500 ) ;
}

function StartSearch()
{
	var link = GetE('txtUrl').value.Trim() ;

	if ( link.length < 3  )
		return ;

	SetSearchMessage( 'searching...' ) ;

	// Make an Ajax search for the pages.
	oEditor.window.parent.sajax_request_type = 'GET' ;
	oEditor.window.parent.sajax_do_call( 'wfSajaxSearchImageFCKeditor', [link], LoadSearchResults ) ;
}

function LoadSearchResults( result )
{
	var results = result.responseText.Trim().split( '\n' ) ;
	var select = GetE( 'xWikiResults' ) ;

	ClearSearch() ;

	if ( results.length == 0 || ( results.length == 1 && results[0].length == 0 ) )
	{
		SetSearchMessage( 'no images found' ) ;
	}
	else
	{
		if ( results.length == 1 )
			SetSearchMessage( 'one image found' ) ;
		else
			SetSearchMessage( results.length + ' images found' ) ;

		for ( var i = 0 ; i < results.length ; i++ )
			FCKTools.AddSelectOption( select, results[i], results[i] ) ;
	}
}

function ClearSearch()
{
	var select = GetE( 'xWikiResults' ) ;

	while ( select.options.length > 0 )
		select.remove( 0 )
}

function SetSearchMessage( message )
{
	GetE('xWikiSearchStatus').innerHTML = message ;
}

function SetUrl( url )
{
	if ( url.length > 0 )
		GetE('txtUrl').value = url ;
}

function UpdatePreviewFromAjax( response )
{
	var eImgPreview = window.document.getElementById('prevImg');
	eImgPreview.src = response.responseText ;
	SetAttribute(eImgPreview, "width" , '180px' ) ;
	SetAttribute(eImgPreview, "height", '130px' ) ;
	//UpdateImage( eImgPreview, response.responseText ) ;
}

function UpdatePreview()
{
	var ajaxArg = GetE('txtUrl').value + '|180x130px';
	oEditor.window.parent.sajax_request_type = 'GET' ;
	oEditor.window.parent.sajax_do_call( 'wfSajaxGetImageUrl', [ajaxArg], UpdatePreviewFromAjax ) ;
}

	</script>
</head>
<body scroll="no" style="overflow: hidden">
    <div id="globalWrapper">
    <div id="innerContent">
	<div id="divInfo">
		<table cellspacing="1" cellpadding="1" border="0" width="100%">
			<tr valign="center">
				<td>
					<span>Image file name</span><br />
					<input id="txtUrl" style="width: 100%" type="text" onkeyup="OnUrlChange();" class="wickEnabled" constraints="ask: [[Image:+]]" />
					<br />
					Automatic search results (<span id="xWikiSearchStatus">start typing in the above field</span>)<br />
					<select id="xWikiResults" size="5" style="width: 100%; height: 70px" onclick="SetUrl( this.value );UpdatePreview();">
					</select>
				</td>
				<td width="180px" height="130px"><div style="width:180; height:130; border:solid 1px black;" valign="center" align="center">
					<img id="prevImg" width="180px" height="130px" alt="Preview"></div>
				</td>
			</tr>
			<tr>
				<td colspan="2">
					<span>Caption</span><br />
					<input id="txtAlt" style="width: 100%" type="text"><br />
				</td>
			</tr>
			<tr>
				<td valign="top" colspan="2">
					<table cellspacing="0" cellpadding="0" border="0">
						<tr>
							<td nowrap="nowrap">
								Special Type<br />
								<select id="xType">
									<option value="" selected="selected"></option>
									<option value="thumb">Thumbnail</option>
									<option value="frame">Frame</option>
									<option value="border">Border</option>
								</select>
							</td>
							<td style="padding-left:7px;">
								<span fcklang="DlgImgAlign">Align</span><br />
								<select id="cmbAlign" onchange="UpdatePreview();">
									<option value="" selected></option>
									<option fcklang="DlgImgAlignRight" value="right">Right</option>
									<option fcklang="DlgImgAlignLeft" value="left">Left</option>
									<option value="center">Center</option>
								</select>
							</td>
							<td style="padding-left:7px;">
								<span fcklang="DlgImgWidth">Width</span><br />
								<input type="text" size="3" id="txtWidth">
							</td>
							<td style="padding-left:7px;">
								<span fcklang="DlgImgHeight">Height</span><br />
								<input type="text" size="3" id="txtHeight">
							</td>
						</tr>
					</table>
				</td>
			</tr>
		</table>
	</div>
    </div>
    </div>
</body>
</html>
